package com.jzr.open.controller.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jzr.common.entity.vo.Result;
import com.jzr.common.util.U;
import com.jzr.open.db1.model.TPatientView;
import com.jzr.open.db1.service.PatientViewService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/patientView")
public class PatientViewController {
    @Autowired
    private PatientViewService patientViewService;

    @PostMapping("/get")
    public Result<List<TPatientView>> get(@RequestBody TPatientView record){
        QueryWrapper<TPatientView> qw = new QueryWrapper<>();

        if(U.isNotBlank(record.getPatientCode())) {
            qw.eq(TPatientView.PatientCode_,record.getPatientCode());
        }
        if(U.isNotBlank(record.getCureNo())){
            qw.eq(TPatientView.CureNo_,record.getCureNo());
        }
        List<TPatientView> list = patientViewService.list(qw);
        return Result.success("成功",list,list==null ? 0:list.size());
    }

    @PostMapping("/post")
    public Result<Integer> post(@RequestBody List<TPatientView> list){
        if(list == null || list.isEmpty()){
            return Result.fail("数据不能为空");
        }
        for(TPatientView record : list){
            if(U.isBlank(record.getPatientCode())){
                return Result.fail("patientCode不能为空");
            }
            if(U.isBlank(record.getCureNo())){
                return Result.fail("cureNo不能为空");
            }
        }
        int count = patientViewService.save(list);
        if(count <= 0){
            return Result.fail("保存失败");
        }else {
            return Result.success("成功",count,count);
        }
    }
//    @PostMapping("/delete")
//    public Result<Integer> delete(@RequestBody List<TPatientView> list){
//        if(list == null || list.isEmpty()){
//            return Result.fail("数据不能为空");
//        }
//        for(TPatientView record : list){
//            if(U.isBlank(record.getCureNo())){
//                return Result.fail("cureNo不能为空");
//            }
//        }
//        int count = patientViewService.delete(list);
//        if(count <= 0){
//            return Result.fail("删除失败");
//        }else {
//            return Result.success("成功",count);
//        }
//    }
}
